package com.ybg.ebs_memory.data;

import java.util.Objects;

public class Product {
    private int id;
    private String name;
    private float price;
    private int categoryId;

    public Product(int id, String name, float price, int categoryId) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.categoryId = categoryId;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public float getPrice() {
        return price;
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void showLine(String category){
        System.out.println(String.format("%d\t%s\t%.2f\t%s"
                ,id,category,price,name));
    }

    public float showCartItem(int count){
        float item = price*count;
        System.out.println(String.format("%d\t%.2f\t%d\t%.2f\t%s"
                ,id,price,count,item,name));
        return item;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return id == product.id && Float.compare(product.price, price) == 0 && categoryId == product.categoryId && Objects.equals(name, product.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, price, categoryId);
    }
}
